import time
from selenium.webdriver.common.by import By
from 测试.common.Utils import Driver

class Login:
    driver=""
    url=""
    def __init__(self):
        self.driver=Driver.driver
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver.get(self.url)
    def Logsuccess(self):
        self.driver.implicitly_wait(1)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lxy")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # 对登录结果进⾏检测, 如果跳转到了博客列表⻚才算是登录成功了

        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-header.d-print-none > div > div")
        Driver.getScreenShot()


    def LoginFailTest(self):
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("adminjjjj")
            self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("111")
            self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
            self.driver.implicitly_wait(1)
            expect = "警告"
            actual = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text
            print(actual)
            Driver.getScreenShot()
            assert expect == actual
# login=Login()
# login.Logsuccess()
# login.loginFailTest()